package packaging.interview.questions;

import java.util.Scanner;
import java.util.Vector;

/**
 * @author shkstart
 * @date 2022/5/15 - 16:43
 */
public class ScoreTestExer {
    public static void main(String[] args) {
        //    1.实例化Scanner 用于从键盘获取学生成绩
        Scanner scanner = new Scanner(System.in);
//    2.创建Vector对象

        Vector v = new Vector();

//    3.for(;;)或while(true)方式，给Vector添加数据
        for(;;) {
            System.out.print("请输入学生成绩(当输入负数时表示结束):");
            Integer inScore = new Integer(scanner.nextInt());
            if(inScore < 0) {
                break;
            }
            if(inScore > 100) {
                System.out.println("输入的成绩非法,请重新输入:");
                continue;
            }
            v.addElement(inScore);
        }

        Object obj = v.elementAt(0);
        Integer integer = (Integer)obj;
        int max = integer.intValue();
        for(int i = 1; i < v.size(); i++) {
            Object o1 = v.elementAt(i);
            Integer i1 = (Integer)o1;
            int j = i1.intValue();
            if(max < i1) {
                max = i1;
            }
        }

        System.out.println("学生成绩的最大值为:" + max);

        for(int i = 0; i < v.size(); i++) {
            Object o1 = v.elementAt(i);
            Integer i1 = (Integer)o1;
            int j = i1.intValue();
            if(max - i1 < 10) {
                System.out.println("第" + (i+1) + "位学生的成绩为" + j + "等级为A");
            }else if(max - i1 < 20) {
                System.out.println("第" + (i+1) + "位学生的成绩为" + j + "等级为B");
            }else if(max - i1 < 30) {
                System.out.println("第" + (i+1) + "位学生的成绩为" + j + "等级为C");
            }else {
                System.out.println("第" + (i+1) + "位学生的成绩为" + j + "等级为D");
            }
        }



    }
}
